# python
from .. import db

from flask_restful import Resource, fields, marshal_with

category_fields = {
    'id': fields.Integer,  # 类别id
    'parent_id': fields.Integer,  # 父类别id
    'name': fields.String,  # 用户名
}

class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    parent_id = db.Column(db.Integer)
    name = db.Column(db.String(80), nullable=False)

    def to_dict(self):
        return {
            'id': self.id,
            'parent_id': self.parent_id,
            'name': self.name,
        }

    def __repr__(self):
        return f'<Category {self.name}>'
